//
//  MainMenu.m
//  ibasketball2D
//
//  Created by imac on 11-5-25.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "CMainMenu.h"
//主菜单

@implementation CMainMenu

//主菜单初始化
-(id)init
{
	if ((self = [super init]))
	{
		[self InitBackground];
		[self InitMenuItem];
		[[CStateManager SharedManager] SetGameState:MainMenu_Run];
	}
	return self;
}

//初始化菜单背景
-(void)InitBackground
{		
	CCSprite* background = [CCSprite spriteWithFile:@"MenuBackground.png"];
	[self addChild:background z:0 tag:kBackground];
	background.anchorPoint = CGPointZero;
	background.position = CGPointZero;
}

//初始化菜单元素
-(void)InitMenuItem
{
	//获取屏幕大小
	CGSize size = [[CCDirector sharedDirector] winSize];
	
	//创建NewGame按钮
	CCSprite* NewGame_normal = [CCSprite spriteWithFile:@"NewGame_normal.png"];
	CCSprite* NewGame_selected = [CCSprite spriteWithFile:@"NewGame_selected.png"];
	CCMenuItemSprite* item1 = [CCMenuItemSprite itemFromNormalSprite:NewGame_normal 
													  selectedSprite:NewGame_selected target:self 
															selector:@selector(NewGameItemTouched:)];
	
	//创建Option按钮
	CCSprite* Option_normal = [CCSprite spriteWithFile:@"Option_normal.png"];
	CCSprite* Option_selected = [CCSprite spriteWithFile:@"Option_selected.png"];
	CCMenuItemSprite* item2 = [CCMenuItemSprite itemFromNormalSprite:Option_normal
													  selectedSprite:Option_selected target:self 
															selector:@selector(OptionItemTouched:)];
	
	//创建Creadits按钮
	CCSprite* Creadits_normal = [CCSprite spriteWithFile:@"Credits_normal.png"];
	CCSprite* Creadits_selected = [CCSprite spriteWithFile:@"Credits_selected.png"];
	CCMenuItemSprite* item3 = [CCMenuItemSprite itemFromNormalSprite:Creadits_normal
													  selectedSprite:Creadits_selected target:self 
															selector:@selector(OptionItemTouched:)];
	//创建菜单
	CCMenu* menu = [CCMenu menuWithItems:item1,item2,item3,nil];
	menu.position = CGPointMake(size.width / 2, size.height / 2);
	
	//添加菜单
	[self addChild:menu z:1 tag:kMenuTag];
	[menu alignItemsVerticallyWithPadding:40];
}

#pragma mark OnTouched Control

-(void)NewGameItemTouched:(id)sender
{
	[[CStateManager SharedManager] SetGameState:Game_Run];
}

-(void)OptionItemTouched:(id)sender
{
	[[CStateManager SharedManager] SetGameState:Option_Run];
}

-(void)CreditsItemTouched:(id)sender
{
	[[CStateManager SharedManager] SetGameState:Credits_Run];
}

@end
